package com.dk.service.Impl;

import com.dk.mapper.TabUserMapper;
import com.dk.pojo.TabUser;
import com.dk.pojo.TabUserExample;
import com.dk.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegisterServiceImpl implements RegisterService {
    @Autowired
    TabUserMapper tabUserMapper;
    @Override
    public int isUserNameExists(String username) {
        TabUserExample example = new TabUserExample();
        TabUserExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<TabUser> tabUsers = tabUserMapper.selectByExample(example);
        if (tabUsers.size()>0){
            return 1;//0表示数据库已经有同名的username
        }
        return 0;//1表示没有
    }

    @Override
    public int saveUser(TabUser user) {
        return tabUserMapper.insertSelective(user);
    }
}
